package cn.yuanqiao.web.controller.archive.wenjianzhengli;

import cn.yuanqiao.archive.appManager.domain.TenantYqFolder;
import cn.yuanqiao.archive.appManager.service.ITenantSysConfigService;
import cn.yuanqiao.archive.wenjianzhengli.annotation.JudgeIsManualAdd;
import cn.yuanqiao.archive.wenjianzhengli.service.ILixianjieshouService;
import cn.yuanqiao.archive.wenjianzhengli.service.ITenantYqdaDocumentService;
import cn.yuanqiao.archive.wenjianzhengli.utils.RedisDistributedLock;
import cn.yuanqiao.common.exception.ServiceException;
import cn.yuanqiao.common.utils.PdfUtils;
import cn.yuanqiao.common.utils.SnowflakeIdGenerator;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @author zjj
 * @date 2023/6/26
 */
@RestController
@RequestMapping("/archive/lxjs")
public class LixianjieshouController extends BaseController {
    @Autowired
    private ILixianjieshouService lixianjieshouService;
    @Autowired
    private ITenantYqdaDocumentService documentService;
    @Autowired
    public RedisTemplate redisTemplate;
    @Autowired
    private ITenantSysConfigService sysConfigService;

    @Value("${identifyType}")
    private String identifyType;

    /**
     * 添加项目
     * @param object
     * @return
     */
    @Log(title = "添加项目", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:addItem')")
    @PostMapping("/addItem")
    public AjaxResult addItem(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.addItem(object);
        return AjaxResult.success();
    }

    @Log(title = "在线接收添加项目", businessType = BusinessType.INSERT)
    //@PreAuthorize("@ss.hasPermi('archive:lxjs:addItemZxjs")
    @JudgeIsManualAdd(type = "3")
    @PostMapping("/addItemZxjs")
    public AjaxResult addItemZxjs(@RequestBody JSONObject object){
        /*JSONArray array = object.getJSONArray("column");
        JSONObject object1 = new JSONObject();
        object1.put("name","JS_TYPE");
        object1.put("value","1");
        array.add(object1);*/
        logger.info(object.toJSONString());
        lixianjieshouService.addItem(object);
        return AjaxResult.success();
    }

    /**
     * 组项目
     * @return
     */
    @Log(title = "组项目", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:mergeFolder')")
    @PostMapping("/mergeFolder")
    public AjaxResult mergeFolder(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.mergeFolder(object);
        return AjaxResult.success();
    }

    /**
     * 拆项目
     * @return
     */
    @Log(title = "拆项目", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:splitItem')")
    @PostMapping("/splitItem")
    public AjaxResult splitItem(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.splitItem(object);
        return AjaxResult.success();
    }

    /**
     * 移除卷和项目关系
     * @return
     */
    @Log(title = "移除卷和项目关系", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:delItemFolderByFolderId')")
    @PostMapping("/delItemFolderByFolderId")
    public AjaxResult delItemFolderByFolderId(@RequestBody JSONObject object){
        lixianjieshouService.delItemFolderByFolderId(object);
        return AjaxResult.success();
    }

    /**
     * 添加卷
     * @param object
     * @return
     */
    @Log(title = "添加卷", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:addFolder')")
    @PostMapping("/addFolder")
    public AjaxResult addFolder(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        TenantYqFolder folder = lixianjieshouService.addFolder(object);
        return AjaxResult.success(folder.getColNames().get("FOLDER_ID"));
    }

    /**
     * 添加卷
     * @param object
     * @return
     */
    @Log(title = "添加卷", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:addFolder1')")
    @PostMapping("/addFolder1")
    public AjaxResult addFolder1(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        TenantYqFolder folder = lixianjieshouService.addFolder(object);
        return AjaxResult.success(folder.getColNames().get("FOLDER_ID"));
    }

    @Log(title = "在线接收添加卷", businessType = BusinessType.INSERT)
    //@PreAuthorize("@ss.hasPermi('archive:lxjs:addFolderZxjs")
    @JudgeIsManualAdd(type = "1")
    @PostMapping("/addFolderZxjs")
    public AjaxResult addFolderZxjs(@RequestBody JSONObject object){
        //判断该门类是否添加IS_MANUAL_ADD 字段
        /*JSONArray array = object.getJSONArray("column");
        JSONObject object1 = new JSONObject();
        object1.put("name","JS_TYPE");
        object1.put("value","1");
        array.add(object1);*/
        logger.info(object.toJSONString());
        TenantYqFolder folder = lixianjieshouService.addFolder(object);
        return AjaxResult.success(folder.getColNames().get("FOLDER_ID"));
    }
    /**
     * 待归档项目层案卷著录保存
     * @param object
     * @return
     */
    @Log(title = "待归档项目层案卷著录保存", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:addFolderDgd')")
    @PostMapping("/addFolderDgd")
    public AjaxResult addFolderDgd(@RequestBody JSONObject object){
        JSONArray array = object.getJSONArray("column");
        JSONObject object1 = new JSONObject();
        object1.put("name","STATE");
        object1.put("value","10");
        array.add(object1);
        logger.info(object.toJSONString());
        TenantYqFolder folder = lixianjieshouService.addFolder(object);
        return AjaxResult.success(folder.getColNames().get("FOLDER_ID"));
    }



    /**
     * 合并卷
     * @param object
     * @return
     */
    @Log(title = "合并卷", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:assemblyFolder')")
    @PostMapping("/assemblyFolder")
    public AjaxResult assemblyFolder(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.assemblyFolder(object);
        return AjaxResult.success();
    }

    /**
     * 合并卷
     * @param object
     * @return
     */
    @Log(title = "验证是否可以合并卷", businessType = BusinessType.UPDATE)
    @PostMapping("/assemblyFolderVerify")
    public AjaxResult assemblyFolderVerify(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        Boolean bl = lixianjieshouService.assemblyFolderVerify(object);
        if (bl == false){
            return AjaxResult.error("选择的卷不在同一个项目下，不能合并卷！");
        }
        return AjaxResult.success("200");
    }


    /**
     * 拆卷
     * @param object
     * @return
     */
    @Log(title = "拆卷", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:splitFolder')")
    @PostMapping("/splitFolder")
    public AjaxResult splitFolder(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.splitFolder(object);
        return AjaxResult.success();
    }

    /**
     * 组卷
     * @return
     */
    @Log(title = "组卷", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:mergeYqda')")
    @PostMapping("/mergeYqda")
    public AjaxResult mergeYqda(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.mergeYqda(object);
        return AjaxResult.success();
    }

    /**
     * 获取组件id
     * @return
     */
    @Log(title = "获取组件id", businessType = BusinessType.SELECT)
    @GetMapping("/getYqdaId")
    public AjaxResult getYqdaId(){
        long id = SnowflakeIdGenerator.generateId();
        return AjaxResult.success(id);
    }

    /**
     * 添加件
     * @param object
     * @return
     */
    @Log(title = "添加件", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:addYqda')")
    @PostMapping("/addYqda")
    public AjaxResult addYqda(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.addYqda(object);
        return AjaxResult.success();
    }
    @Log(title = "在线接收添加件", businessType = BusinessType.INSERT)
    //@PreAuthorize("@ss.hasPermi('archive:lxjs:addYqdaZxjs")
    @JudgeIsManualAdd(type = "0")
    @PostMapping("/addYqdaZxjs")
    public AjaxResult addYqdaZxjs(@RequestBody JSONObject object){
        /*JSONArray array = object.getJSONArray("column");
        JSONObject object1 = new JSONObject();
        object1.put("name","JS_TYPE");
        object1.put("value","1");
        array.add(object1);*/
        logger.info(object.toJSONString());
        lixianjieshouService.addYqda(object);
        return AjaxResult.success();
    }

    @Log(title = "在线接收添加卷内", businessType = BusinessType.INSERT)
    //@PreAuthorize("@ss.hasPermi('archive:lxjs:addYqdaZxjs2")
    @JudgeIsManualAdd(type = "0")
    @PostMapping("/addYqdaZxjs2")
    public AjaxResult addYqdaZxjs2(@RequestBody JSONObject object){
        /*JSONArray array = object.getJSONArray("column");
        JSONObject object1 = new JSONObject();
        object1.put("name","JS_TYPE");
        object1.put("value","1");
        array.add(object1);*/
        logger.info(object.toJSONString());
        lixianjieshouService.addYqda(object);
        return AjaxResult.success();
    }


    /**
     * 添加件--卷内件著录
     * @param object
     * @return
     */
    @Log(title = "添加件", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:addYqda1')")
    @PostMapping("/addYqda1")
    public AjaxResult addYqda1(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.addYqda(object);
        return AjaxResult.success();
    }

    @Log(title = "待归档项目层案卷著录卷内件著录保存", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:addYqdaDgd')")
    @PostMapping("/addYqdaDgd")
    public AjaxResult addYqdaDgd(@RequestBody JSONObject object){
        JSONArray array = object.getJSONArray("column");
        JSONObject object1 = new JSONObject();
        object1.put("name","STATE");
        object1.put("value","10");
        array.add(object1);
        logger.info(object.toJSONString());
        lixianjieshouService.addYqda(object);
        return AjaxResult.success();
    }
    /**
     * 修改项目
     * @param object
     * @return
     */
    @Log(title = "修改项目", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:updateItem')")
    @PostMapping("/updateItem")
    public AjaxResult updateItem(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.updateItem(object);
        return AjaxResult.success();
    }

    /**
     * 修改项目
     * @param object
     * @return
     */
    @Log(title = "修改项目", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:updateItem1')")
    @PostMapping("/updateItem1")
    public AjaxResult updateItem1(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.updateItem(object);
        return AjaxResult.success();
    }

    /**
     * 修改项目
     * @param object
     * @return
     */
    @Log(title = "修改项目", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:updateItem2')")
    @PostMapping("/updateItem2")
    public AjaxResult updateItem2(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.updateItem(object);
        return AjaxResult.success();
    }

    /**
     * 修改组卷
     * @param object
     * @return
     */
    @Log(title = "修改组卷", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:updateFolder')")
    @PostMapping("/updateFolder")
    public AjaxResult updateFolder(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.updateFolder(object);
        return AjaxResult.success();
    }

    /**
     * 修改组卷
     * @param object
     * @return
     */
    @Log(title = "修改组卷", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:updateFolder1')")
    @PostMapping("/updateFolder1")
    public AjaxResult updateFolder1(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.updateFolder(object);
        return AjaxResult.success();
    }

    /**
     * 修改组卷
     * @param object
     * @return
     */
    @Log(title = "修改组卷", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:updateFolder2')")
    @PostMapping("/updateFolder2")
    public AjaxResult updateFolder2(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.updateFolder(object);
        return AjaxResult.success();
    }

    /**
     * 修改组卷
     * @param object
     * @return
     */
    @Log(title = "修改组卷", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:updateFolder3')")
    @PostMapping("/updateFolder3")
    public AjaxResult updateFolder3(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.updateFolder(object);
        return AjaxResult.success();
    }
    /**
     * 待归档项目层案卷修改
     * @param object
     * @return
     */
    @Log(title = "待归档项目层案卷修改", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:updateFolderDgd')")
    @PostMapping("/updateFolderDgd")
    public AjaxResult updateFolderDgd(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.updateFolder(object);
        return AjaxResult.success();
    }

    /**
     * 修改组件
     * @param object
     * @return
     */
    @Log(title = "修改组件", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:updateYqda')")
    @PostMapping("/updateYqda")
    public AjaxResult updateYqda(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.updateYqda(object);
        return AjaxResult.success();
    }

    /**
     * 修改组件
     * @param object
     * @return
     */
    @Log(title = "修改组件", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:updateYqda1')")
    @PostMapping("/updateYqda1")
    public AjaxResult updateYqda1(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.updateYqda(object);
        return AjaxResult.success();
    }

    /**
     * 修改组件
     * @param object
     * @return
     */
    @Log(title = "修改组件", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:updateYqda2')")
    @PostMapping("/updateYqda2")
    public AjaxResult updateYqda2(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.updateYqda(object);
        return AjaxResult.success();
    }

    @Log(title = "在线接收修改卷内", businessType = BusinessType.UPDATE)
    //@PreAuthorize("@ss.hasPermi('archive:lxjs:updateYqdaZxjs")
    @PostMapping("/updateYqdaZxjs")
    public AjaxResult updateYqdaZxjs(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.updateYqda(object);
        return AjaxResult.success();
    }
    /**
     * 待归档项目层案卷著录卷内件修改
     * @param object
     * @return
     */
    @Log(title = "待归档项目层案卷著录卷内件修改", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('archive:lxjs:updateYqdaDgd')")
    @PostMapping("/updateYqdaDgd")
    public AjaxResult updateYqdaDgd(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.updateYqda(object);
        return AjaxResult.success();
    }
    /**
     * 修改组件
     * @param object
     * @return
     */
    @Log(title = "绑定卷和件的关系", businessType = BusinessType.UPDATE)
    @PostMapping("/bindFolderIdDaId")
    public AjaxResult bindFolderIdDaId(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        lixianjieshouService.bindFolderIdDaId(object);
        return AjaxResult.success();
    }

    /**
     * 获取项目
     * @param object
     * @return
     */
    @Log(title = "获取项目", businessType = BusinessType.SELECT)
    @PostMapping("/getItemById")
    public AjaxResult getItemById(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        Map<String,Object> data = lixianjieshouService.getItemById(object);
        return AjaxResult.success(data);
    }

    /**
     * 获取卷层
     * @param object
     * @return
     */
    @Log(title = "获取卷层", businessType = BusinessType.SELECT)
    @PostMapping("/getFolderById")
    public AjaxResult getFolderById(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        Map<String,Object> data = lixianjieshouService.getFolderById(object);
        return AjaxResult.success(data);
    }

    /**
     * 获取件层
     * @param object
     * @return
     */
    @Log(title = "获取件层", businessType = BusinessType.SELECT)
    @PostMapping("/getYqdaById")
    public AjaxResult getYqdaById(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        Map<String,Object> data = lixianjieshouService.getYqdaById(object);
        return AjaxResult.success(data);
    }

    /**
     * 文件上传请求
     */
    @Log(title = "电子文件上传", businessType = BusinessType.INSERT)
    @PostMapping("/upload")
    public AjaxResult upload(@RequestParam("categoryId")Long categoryId,@RequestParam("daId")Long daId,
                             @RequestParam("type")Integer type,@RequestParam("fields")String fields,MultipartFile file)
    {
        String daIdStr = String.valueOf(daId);
        //分布式锁，同时上传只能上传不同的件档案，如果上传的是一个档案下的件则必须等上一个上传完成
        RedisDistributedLock lock = new RedisDistributedLock(redisTemplate, "uploadFileKey:"+daIdStr, UUID.randomUUID().toString());
        try {
            logger.info("获取分布式锁："+"uploadFileKey:"+daIdStr);
            while (!lock.lock()) {
                logger.info("线程等待中："+"uploadFileKey:"+daIdStr);
                Thread.sleep(500);
            }
            logger.info("开始上传："+"uploadFileKey:"+daIdStr);
            JSONObject msg = documentService.uploadFile(categoryId,daId,type,fields,file);
            return AjaxResult.success(msg);
        }catch (Exception e){
            logger.error("上传文件失败", e);
            return AjaxResult.error("上传失败！"+e.getMessage());
        }finally {
            logger.info("解除锁："+"uploadFileKey:"+daIdStr);
            lock.unlock();
        }
    }

    /**
     * 获取电子文件信息
     * @param object
     * @return
     */
    @Log(title = "获取电子文件信息", businessType = BusinessType.SELECT)
    @PostMapping("/getDocumentById")
    public AjaxResult getDocumentById(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        Map<String,Object> data = documentService.getDocumentById(object);
        return AjaxResult.success(data);
    }

    /**
     * 修改电子文件信息
     * @param object
     * @return
     */
    @Log(title = "修改电子文件信息", businessType = BusinessType.UPDATE)
    @PostMapping("/updateDocument")
    public AjaxResult updateDocument(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        if(object.toJSONString().indexOf("FILE_ONLY_VAL")>-1){
            throw new ServiceException("非法参数");
        }
        documentService.updateDocument(object);
        return AjaxResult.success();
    }

    /**
     * 删除电子文件信息
     * @param ids
     * @return
     */
    @Log(title = "删除电子文件信息", businessType = BusinessType.DELETE)
    @PostMapping("/delDocument")
    public AjaxResult delDocument(@RequestParam("categoryId")Long categoryId,@RequestParam("daId")Long daId,@RequestParam("ids") Long [] ids){
        documentService.delDocument(categoryId,ids,daId);
        return AjaxResult.success();
    }

    /**
     * 档案接收
     */
    @Log(title = "档案接收", businessType = BusinessType.UPDATE)
    @PostMapping("jieshou")
    @PreAuthorize("@ss.hasPermi('archive:lxjs:jieshou')")
    public AjaxResult jieshou(@RequestParam("categoryId")Long categoryId,@RequestParam("ids")Long[] ids)
    {
        lixianjieshouService.jieshou(categoryId,ids);
        return AjaxResult.success();
    }

    @Log(title = "接收至待归档", businessType = BusinessType.UPDATE)
    @PostMapping("jieshou2")
    @PreAuthorize("@ss.hasPermi('archive:lxjs:jieshou2')")
    public AjaxResult jieshou2(@RequestParam("categoryId")Long categoryId,@RequestParam("ids")Long[] ids)
    {
        lixianjieshouService.jieshou2(categoryId,ids);
        return AjaxResult.success();
    }

    /**
     * 根据档案id,门类id获取电子文件信息
     * @param object
     * @return
     */
    @Log(title = "根据档案id,门类id获取电子文件信息", businessType = BusinessType.SELECT)
    @PostMapping("/getDocumentBydaId")
    public AjaxResult getDocumentBydaId(@RequestBody JSONObject object){
        logger.info(object.toJSONString());
        List<Map<String,Object>> data = documentService.getDocumentBydaId(object);
        return AjaxResult.success(data);
    }

    @Log(title = "ofd定时转换", businessType = BusinessType.OTHER)
    @GetMapping("/docToOfdTask")
    public AjaxResult docToOfdTask(@RequestParam("tenantCode") String tenantCode){
        documentService.docToOfdTask(tenantCode);
        return AjaxResult.success();
    }


    @Log(title = "ofd转换", businessType = BusinessType.OTHER)
    @PostMapping("/docToOfd")
    public AjaxResult docToOfd(@RequestParam("docId") Long docId,@RequestParam("categoryId") Long categoryId){
        try {
            documentService.docToOfd(docId,categoryId);
            return AjaxResult.success();
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
        }
        return AjaxResult.error("转换失败");
    }

   /* @GetMapping("/testPdfToImg")
    public AjaxResult testPdfToImg(@RequestParam("pdfPath") String pdfPath){
        try {
            List<String> list = PdfUtils.pdf2Img(pdfPath);
            return AjaxResult.success(list);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
        }
        return AjaxResult.error("转换失败");
    }*/


    @Log(title = "识别", businessType = BusinessType.OTHER)
    @PostMapping("/identify")
    public AjaxResult identify(@RequestParam("docId") Long docId,@RequestParam("categoryId") Long categoryId){
        String line="";
        String ishdyyofd = sysConfigService.selectConfigByKey("ISHDYYOFD");
        Map map=new HashMap();
     try {
        if("true".equalsIgnoreCase(ishdyyofd)){
            documentService.identifyHdyy(docId,categoryId);
        }else{
            if("pdf".equals(identifyType)){
                line= documentService.identifyPdf(docId, categoryId);
            }else {
                documentService.identify(docId, categoryId);
            }
            map.put("title",line);
        }
         return AjaxResult.success(map);

     } catch (Exception e) {
         e.printStackTrace();
     }
        return AjaxResult.error("识别失败");
    }
    //定时转换
    @Log(title = "定时识别", businessType = BusinessType.OTHER)
    @GetMapping("/identifyTask")
    public AjaxResult identifyTask(@RequestParam("tenantCode") String tenantCode,@RequestParam(value = "categoryId",required = false) String categoryId){
        documentService.identifyTaskAll(tenantCode,categoryId);
        return AjaxResult.success();
    }

    /**
     * 预归档退回
     * @param categoryId
     * @param ids
     * @return
     */
    @PostMapping("/tuihui")
    public AjaxResult tuihui(@RequestParam("categoryId") Long categoryId,@RequestParam("ids") Long [] ids){
        lixianjieshouService.tuihui(categoryId,ids);
        return AjaxResult.success();
    }

    /**
     * 提交按钮
     */
    @GetMapping("/submit/button")
    @PreAuthorize("@ss.hasPermi('archive:lxjs:tijiao')")
    public AjaxResult submitButton(@RequestParam("categoryId") Long categoryId,@RequestParam("ids")List<String> idList) {
        lixianjieshouService.submitButton(categoryId, idList);
        return AjaxResult.success();
    }

    @PostMapping("/updateBgqx")
    @PreAuthorize("@ss.hasPermi('archive:lxjs:updateBgqx')")
    public AjaxResult updateBgqx(@RequestBody JSONObject object) {
        String bgqxVal = object.getString("bgqxVal");
        String ids = object.getString("ids");
        Long categoryId = object.getLong("categoryId");
        String type = object.getString("type");
        lixianjieshouService.updateBgqx(bgqxVal, ids, type,categoryId);
        return AjaxResult.success();
    }

    /***
     * 修改文件密级
     */
    @PostMapping("/changeFileMj")
    public AjaxResult changeFileMj(@RequestBody JSONObject object) {
        Long daId = object.getLong("daId");
        Long categoryId = object.getLong("categoryId");
        Long docId = object.getLong("docId");
        String mj = object.getString("mj");
        return AjaxResult.success(lixianjieshouService.changeFileMj(daId,categoryId,docId,mj));
    }
}
